﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.Data.SqlClient;
using ECONTACT.Controller;

namespace ECONTACT
{
    public partial class frmHocSinh : Form
    {
        PhuHuynhCtrl m_PhuHuynhCtrl = new PhuHuynhCtrl();
        HocSinhCtrl m_HocSinhCtrl = new HocSinhCtrl();
        public frmHocSinh()
        {
            InitializeComponent();
        }

        private void frmHocSinh_Load(object sender, EventArgs e)
        {          
            m_PhuHuynhCtrl.HienThiComboBoxTen(cmbMaPhuHuynh);
            m_HocSinhCtrl.HienThi(dGVHocSinh, txtMaHS, txtTenHS, txtGioiTinh, ckbGTinhNam, ckbGTinhNu, dtpNgaySinh, txtNoiSinh, txtDiaChi, cmbMaPhuHuynh);
        }

        private void dGVHocSinh_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (txtGioiTinh.Text == "True")
                ckbGTinhNu.Checked = true;
            else
                ckbGTinhNam.Checked = true;
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            bool gioiTinh = false;
            if (ckbGTinhNu.Checked == true)
                gioiTinh = true;

            String rs = m_HocSinhCtrl.LuuHocSinh(txtTenHS.Text, gioiTinh, dtpNgaySinh.Value, txtNoiSinh.Text, txtDiaChi.Text, cmbMaPhuHuynh.SelectedValue.ToString());
            if (!rs.Equals("Success"))
            {
                MessageBox.Show(rs);
            }
            
            m_HocSinhCtrl.HienThi(dGVHocSinh, txtMaHS, txtTenHS, txtGioiTinh, ckbGTinhNam, ckbGTinhNu, dtpNgaySinh, txtNoiSinh, txtDiaChi, cmbMaPhuHuynh);
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            bool gioiTinh = false;
            if (ckbGTinhNu.Checked == true)
                gioiTinh = true;

            String rs = m_HocSinhCtrl.UpdateHocSinh(txtMaHS.Text, txtTenHS.Text, gioiTinh, dtpNgaySinh.Value, txtNoiSinh.Text, txtDiaChi.Text, cmbMaPhuHuynh.SelectedValue.ToString());
            if (!rs.Equals("Success")) {
                MessageBox.Show(rs);
            }
            m_HocSinhCtrl.HienThi(dGVHocSinh, txtMaHS, txtTenHS, txtGioiTinh, ckbGTinhNam, ckbGTinhNu, dtpNgaySinh, txtNoiSinh, txtDiaChi, cmbMaPhuHuynh);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (dGVHocSinh.RowCount == 0)
            {
                MessageBox.Show("Bạn chưa chọn dòng nào làm sao xóa!", "Thông báo");
            }
            else if (MessageBoxEx.Show("Bạn có chắc là xóa thiệt hok ?", "DELETE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                m_HocSinhCtrl.DeleteHocSinh(txtMaHS.Text);
                m_HocSinhCtrl.HienThi(dGVHocSinh, txtMaHS, txtTenHS, txtGioiTinh, ckbGTinhNam, ckbGTinhNu, dtpNgaySinh, txtNoiSinh, txtDiaChi, cmbMaPhuHuynh);
            }
        }
    }
}
